%{	
#include <stdio.h>
#include<math.h>
double val = (3.14159265 / 180.0);
%}
%union{
int i;
float f;
double d;
}
%token <i> SIN COS TAN LOG SQRT
%token <i> NUM
%type <d> E 
%type <d> S
%left '+' '-'
%left '*' '/'
%right '^'

%%
S : E '\n' {$$ = $1; printf("Result : %lf", (double)$$);}
;
E : E '+' E {$$ = $1 + $3;}
 | E '-' E {$$ = $1 - $3;}
 | E '*' E {$$ = $1 * $3;}
 | E '/' E {$$ = $1 / $3;}	
 | E '^' E {$$ = pow($1, $3);}
 | SIN'(' E ')' {$$ = sin((double)$3 * val);}//printf("$3 : %lf, val : %lf, angle : %lf", (double)$3, val, ((double)$3 * val));}
 | COS'(' E ')' {$$ = cos((double)$3 * val);}
 | TAN'(' E ')' {$$ = tan((double)$3 * val);}
 | LOG'(' E ')' {$$ = log($3);}
 | SQRT'(' E ')' {$$ = sqrt($3);}
 | NUM {$$ = $1;}
;
%%

int yyerror(char *s)
{
	return 0;
}

int main()
{
	while(1)
		yyparse();
	return 0;	
}
